//
//  MCCreateApi.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/5/31.
//

import Foundation
import Moya
import SwiftyJSON
import ObjectMapper

enum MCCreateApi {
    case createPlan(planUrl:String?,planNeedTime:Int?,planName:String?,introduce:String?,actionType:Int?,planBgm:String?,planBgmId:String?,actionPlanDetailList:Array<MCCreatePlanCompleteDataActionModel>)
   
}

extension MCCreateApi:TargetType {
    
    var baseURL: URL {
        return URL.init(string: Moya_baseURL)!
    }
    
    var path: String {
        switch self {
        case .createPlan:
            return "api/admin/planForApp/addActionPlan"
        }
    }
    var method:Moya.Method {
        switch self {
        case .createPlan:
            return .post
       
       
        }
    }
    
    var sampleData: Data {
        return Data()
    }
    
    
    var task: Task {
        switch self {
        case let .createPlan(planUrl, planNeedTime, planName, introduce, actionType, planBgm, planBgmId,actionPlanDetailList):
            
            
            print("-------------------------\(actionPlanDetailList.count as Any)------------------------")
            
            let userArray:[[String:Any]] = actionPlanDetailList.toJSON()
            
            var params:Dictionary<String,Any> = ["planUrl":planUrl ?? "","planType":1,"planName":planName ?? "","introduce":introduce ?? "","actionType":actionType ?? 0,"planBgm":planBgm ?? "","planBgmId":planBgmId ?? "","actionPlanDetailList":userArray]
            
            if actionType == 0 {
                params["planNeedTime"] = planNeedTime
            }else{
                params["planNeedTime"] = 0
            }
            
            print(params as Any)
            
            return .requestParameters(parameters:params, encoding: JSONEncoding.default)
        }
    }
    
    var headers: [String : String]? {
        let tokenName:String = UserDefaults.standard.string(forKey: "LoginName") ?? ""
        let tokenValue:String = UserDefaults.standard.string(forKey: "LoginToken") ?? ""
        return [tokenName:tokenValue]
    }
    
    
}
